package collection;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;


public class ListDelete {
	
public static void main(String[] args) {
	 List<String> list = new ArrayList<String>(); 
	 list.add("aa");
	 list.add("bbb");
	 list.add("ccc");
	 list.add("2344");
	 list.add("2222");
	 
     System.out.println(list);
//     simpleDelete(list);
//     deleteFor(list);
     copylistDelete(list);

	 System.out.println(list);
	System.out.println(list);
}

private static void deleteFor(List<String> list) {
	for(String x:list){
	    if(x.equals("ccc"))
	        list.remove(x);
	}

}

private static void simpleDelete(List<String> list) {
	for(int i=0;i<list.size();i++){
	    if(list.get(i).equals("ccc")) {
	    	list.remove(i);
	    	System.out.println("删除元素成功！");
	    }
	}

}

private static void copylistDelete(List<String> cowList) {
	CopyOnWriteArrayList<String> list = new CopyOnWriteArrayList<String>(cowList);
	for(String x:list){
	    if(x.equals("ccc"))
	        list.remove(x);
	}
	System.out.println(list    );

}


}
